<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function Person(name, age) {
        this.name = name;
        this.age = age;
        this.show = function(){
            console.log(this.name);
        }
      }
      Person.prototype.sex = "男";
      Person.prototype.work = function (workType) {
        console.log(this.name + "的工作是：" + workType);
      };
      var p1 = new Person("王大头", 18);
      /* 1）in  判断指定属性或方法是否为该对象的属性或方法，不管是不是本地属性。 */
      console.log("name" in p1);//true
      console.log("sex" in p1);//true
      console.log("work" in p1);//true
      console.log("addr" in p1);//false
      /* 2）delete  用于删除对象对其属性的引用，当属性失去引用之后会被垃圾回收，不再存在。 */
      console.log(p1);
      delete p1.name; //name属性被删除
      delete p1.show; //show()方法可以被删除
      delete p1.work; //私有方法可以被删除，原型方法不能被删除
      console.log(p1);

      var p2 = new Person("张三","56");
      console.log(p2);
      /* 3）instanceof  判断一个实例是否属于某种类型。 */
      console.log(p1 instanceof Person);//true
      console.log(p1 instanceof Object);//true
      console.log(p1 instanceof String);//false
      console.log([] instanceof Array);//true
    </script>
  </body>
</html>
